IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_DashboardSelectForUser]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_DashboardSelectForUser]
GO
create procedure [dbo].[cms_sp_DashboardSelectForUser]
@UserId int,
@SiteGroupId int = null,
@SiteId int = null
as
select 
	[DashboardId] as Id,
    [DashboardName],
    [Description],
    [LoadUrl],
    [AdminUrl],
	[DashboardWidth] as Width,
    [CreatedBy],
    [DateCreated],
    [LastUpdatedBy],
    [DateLastUpdated]
from [dbo].[Dashboards]
where Dashboards.DashboardId in
	(select DashboardGroupLinks.DashboardId from dbo.DashboardGroupLinks
	inner join dbo.UserGroupLinks
	on DashboardGroupLinks.UserGroupId = UserGroupLinks.UserGroupId
	where UserGroupLinks.UserId = @UserId)

GO

